package br.edu.univas.es2012.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.ArrayList;


import javax.swing.ImageIcon;
import javax.swing.JButton;

import br.edu.univas.es2012.listeners.ButtonsListarListener;

public class PanelListaButtons extends JButton{
	private static final long serialVersionUID = 1L;
	
	private JButton fecharButton;
	
	private ArrayList<ButtonsListarListener> listeners = new ArrayList<ButtonsListarListener>();
	
	public PanelListaButtons() {
		super();
		initialize();
	}

	private void initialize() {
		add(getFecharButton());
		
	}

	private JButton getFecharButton() {
		if(fecharButton == null){
			URL caminho = getClass().getResource("/Imagens/cancel.png");
			fecharButton = new JButton("Fechar",new ImageIcon(caminho));
			fecharButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					for(ButtonsListarListener listener: listeners){
						listener.fechar();
					}
					
				}
			});
		}
		return fecharButton;
	}
	
	public void addButtonsListarListener(ButtonsListarListener listener){
		if(listener != null){
			listeners.add(listener);
		}
	}
	
	
	
	

}
